package com.strong.model;

import cn.hutool.core.util.StrUtil;
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.Setter;

/**
 * 位置 模型
 *
 * @author simen
 * @date 2023/04/06
 */
@Getter
@Setter
@NoArgsConstructor
public class Place extends BaseModel {

    public static final String STR_COMPARTMENT = "区划";

    /**
     * 省级行政区代码
     */
    private String provinceCode;

    /**
     * 省级行政区
     */
    private String province;

    /**
     * 地级行政区代码
     */
    private String cityCode;

    /**
     * 地级行政区
     */
    private String city;

    /**
     * 县级行政区代码
     */
    private String countyCode;

    /**
     * 县级行政区
     */
    private String county;

    /**
     * 街道代码
     */
    private String streetCode;

    /**
     * 街道
     */
    private String street;

//    /**
//     * 区号
//     */
//    private String areaCode;
//
//    /**
//     * 邮政编码
//     */
//    private String postalCode;

    /**
     * 地址详情-完整的
     */
    private String addressDetail;

    /**
     * 设置地址细节
     */
    public void setAddressDetail() {
        this.addressDetail = String.format("%s%s%s%s",
                this.province, this.city, this.county, this.street);
    }

    /**
     * 实例化
     *
     * @param provinceCode 省代码
     * @param province     省
     * @param cityCode     城市代码
     * @param city         城市
     * @param countyCode   县代码
     * @param county       县
     * @param streetCode   街代码
     * @param street       街
     */
    public Place(String provinceCode, String province, String cityCode, String city,
                 String countyCode, String county, String streetCode, String street) {
        this.provinceCode = provinceCode;
        this.province = province;

        this.city = StrUtil.contains(city, STR_COMPARTMENT) ? "" : city;
        this.cityCode = cityCode;

        this.county = StrUtil.contains(county, STR_COMPARTMENT) ? "" : county;
        this.countyCode = countyCode;

        this.street = StrUtil.contains(street, STR_COMPARTMENT) ? "" : street;
        this.streetCode = streetCode;

        setAddressDetail();
    }

    /**
     * 获取身份证区域编码
     *
     * @return {@link String}
     */
    public String getIdPlaceCode() {
        return StrUtil.sub(this.countyCode, 0, 6);
    }
}
